#--------------------------------------------------------------------------------------------------------------------------------------------------------
#
# Mi-DevEnv			:	http://midevenv.codeplex.com 
#					:	(c) IT Bridge 2012
#					:	A concept originated by Chris Nurse
#
# Licence			:	GNU General Public License version 2 (GPLv2)
#					:	http://midevenv.codeplex.com/license
#
# Summary           :   Install CRM 2011
#
#--------------------------------------------------------------------------------------------------------------------------------------------------------

Set-StrictMode -Version Latest

if ((Get-Module MDE-Common) -eq $null) {
    Import-Module MDE-Common
    }

[string]$executionPath = Split-Path $script:MyInvocation.MyCommand.Path -Parent
[bool]$needDC = $true
[bool]$needWebServer = $true

Function InstallProduct() {

    if (Get-RunInstallation -Package GetPackageName -RequireDC $needDC -RequireIIS $needWebServer) {

        Add-ServiceAccounts -Product CRM

        Add-DomainUserToLocalGroup "Performance Log Users" "MDE_DOMAIN_NAME/SvcCrmAppSvcAcc"
        Add-DomainUserToLocalGroup "Performance Log Users" "MDE_DOMAIN_NAME/SvcCrmAsnSvcAcc"

        Add-OrganisationalUnit -OUName "MDE_CRM_OU_NAME" -Path "DC=MDE_DOMAIN_NAME,DC=local"
    
        & $InstallFolder\CRM2011\Server\amd64\SetupServer.exe /Q /CONFIG $executionPath\ResponseCrm2011.xml
        Wait-SetupComplete "SetupServer"

        Write-Progress "Install CRM 2011 Reporting Extensions"
        & $InstallFolder\CRM2011\Server\amd64\SrsDataConnector\SetupSrsDataConnector.exe /Q /CONFIG $executionPath\ResponseCrm2011RepExt.xml
        Wait-SetupComplete "SetupSrsDataConnector"
        }
    }

#region Framework

Function GetInstallName() {
    return "Microsoft Dynamics CRM Server 2011"
    }
    
Function GetRequireRestart() {
    return $true
    }

Function GetPackageName() {
    return "CRM2011"
    }

Function GetPackageDescription() {
    return "Dynamics CRM 2011"
    }
    
Function GetServerBuild() {
    return $false 
    }
        
Function GetInstallPriority() {
    return 50000
    }

#endregion